from tkinter import W
import pygame
import random

pygame.init()

USER_EVENT = pygame.event.get()


class GameSprite(pygame.sprite.Sprite, object):

    def __init__(self, image_path, spawnpoint=(0, 0), speed=1) -> None:
        super().__init__()
        self.image = pygame.image.load(image_path)
        self.rect = self.image.get_rect()
        self.speed = speed
        self.spawnpoint = spawnpoint
        self.reset()

    # def update(self):
    #     self.rect.x -= self.speed

    def reset(self):
        self.rect.x, self.rect.y = self.spawnpoint


class player_1(GameSprite):
    def __init__(self, image_path, spawnpoint=(0, 0), speed=1) -> None:
        super().__init__(image_path, spawnpoint, speed)
        

    def update(self):
        self.key = pygame.key.get_pressed()
        # print(self.key)
        if self.key[pygame.K_UP]:
            print("W")
            self.rect.x += self.speed
        elif self.key[pygame.K_LEFT]:
            print("A")
            self.rect.y -= self.speed
        elif self.key[pygame.K_DOWN]:
            print("S")
            self.rect.y -= self.speed
        elif self.key[pygame.K_RIGHT]:
            print("D")
            self.rect.x += self.speed
        else:
            pass


class enemy(GameSprite, object):
    def __init__(self, image_path) -> None:
        super().__init__("./source/ene.png")
        self.image = pygame.image.load(image_path)
        self.rect = self.image.get_rect()
        self.speed = random.randint(1, 10)
        self.spawnpoint = (1920, random.randint(0, 864))
        self.reset()

    def update(self):
        if self.rect.x >= -1920:
            super().update()
        else:
            self.kill()


class bullet(GameSprite):
    pass


class bg(GameSprite):
    def update(self):
        if self.rect.x >= -1920:
            self.rect.x -= self.speed
        else:
            self.rect.x = 1920
